<?php


namespace App\Logic;
use App\Models\Login;
use Illuminate\Support\Facades\Redis;

class RegisterLogic
{
    public static function doregister($data){
        //获取手机号存入Redis
        $code = Redis::get('register_' . $data['phone']);
        //验证短信验证码是否正确
        if ($code != $data['code']) {
            //验证失败
            return response()->json(['code'=>'fail','message'=>"短信验证码输入错误"]);
        }
        //接收密码
        $password=$data['password'];
        //接收确认密码
        $repassword=$data['repassword'];
        //判断密码与确认密码是否一致
        if($password!=$repassword){
            return response()->json(['code'=>'fail','message'=>"确认密码与密码不一致,请重新输入"]);
        }
        //注册时对用户名进行关键词过滤(百度云审核)
        $appId = "30392972";
        $apiKey = "TGOe2dNl7h4fpQsHNDA8apIH";
        $secretKey = "papPfKaeRCrQuBq6ZaSQKz5HVsARW48Y";
        $client = new \Luffy\TextCensor\Core($appId, $apiKey, $secretKey);
        $res = $client->textCensorUserDefined($data['username']); //待审核文本字符串
        if($res['conclusion'] == "不合规") {
            return response()->json(['code'=>'fail','message'=>'注册失败：用户名不合规,请重新输入']);
        };
        //通过模型进行添加入库
//        Login::create([
//            'username' => $data['username'],
//            'phone' => $data['phone'],
//            'password' => md5($data['password']),//对密码进行md5加密
//            'status'=>1
//        ]);

    }
}
